package com.protocolterminal.AFN;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import com.protocolterminal.AFN.entity.AFN0DF221;
import com.protocolterminal.AFN.entity.Interface_Data;

public class AFN0Dwater extends BaseAFN {

	public AFN0Dwater(String framedata) {

		this.AFN = framedata.substring(0, 2);
		this.SEQ = framedata.substring(2, 4);
		List<String> dalist = new ArrayList<>();
		dalist.add(framedata.substring(4, 8));
		this.DA = dalist;
		List<String> dtlist = new ArrayList<>();
		dtlist.add(framedata.substring(8, 12));
		this.DT = dtlist;

		int i = 12;
		List<String> datalist = new ArrayList<>();
		try {
			switch (this.DT.get(0)) {
			case "101B":// 日冻结数据
				Interface_Data data = new AFN0DF221();
				datalist.add(data.frametolist(framedata.substring(12)));
				i += 34 * 2;
				break;
			default:
				break;
			}
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}
		this.Data = datalist;

		this.AUX = framedata.substring(i);

	}

	public AFN0Dwater(String AFN, String SEQ, List<String> DA, List<String> DT, List<String> Data, String AUX) {
		this.AFN = AFN;
		this.SEQ = SEQ;
		this.DA = DA;
		this.DT = DT;
		this.Data = Data;
		this.AUX = "";

	}

	@Override
	public String toString() {
		String data = "";
		try {
			for (int i = 0; i < DA.size(); i++) {
				String datatemp = "";
				Interface_Data interface_Data = null;
				switch (DT.get(i)) {
				case "101B":// 日冻结
					interface_Data = new AFN0DF221();
					break;
				default:
					break;
				}
				datatemp = interface_Data.listtoframe(Arrays.asList(Data.get(i).split("-")));

				data += this.DA.get(i) + this.DT.get(i) + datatemp;
			}
		} catch (Exception e) {
			System.err.println(e.getMessage());
		}

		return this.AFN + this.SEQ + data + this.AUX;
	}

}
